﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MakeItWeb.Framework;
using System.Web.Security;
using System.Security;

namespace AllNations
{
    public partial class MembershipConfirmation : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Request.QueryString["ID"]))
            {
                Response.Redirect("~/Home", true);
                return;
            }
            try
            {
                var member = Member.GetMemberByConfirmationGuid(new Guid(Request.QueryString["ID"]));
                if (!member.Loaded)
                    throw new SecurityException("Invalid confirmation URL.");

                member.ConfirmationGuid = Guid.Empty;
                member.Save();

                FormsAuthentication.SetAuthCookie(member.UsernameTxt, true);

                ClientScript.RegisterStartupScript(GetType(), "user_profile", "window.location='/MyProfile';", true);
            }
            catch (Exception)
            {
                Response.Redirect("~/Home", true);
                return;
            }
        }
    }
}